package com.ws.mapper;

import com.ws.domain.Admins;
import com.ws.domain.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface GoodsDao {

    @Select("select * from goods")
     List<Goods> findAll();

//    @Select("select * from goods limit #{start}, #{size}")
//    List<Goods> goodList(@Param("start") int start, @Param("size") int size);

//统计商品数量
    @Select("select count(*) from goods")
    long getCount();

//    添加商品
@Insert("insert into goods values(null, #{cover}, #{name}, #{intro}, #{spec}, #{price}, #{stock}, #{sales}, #{content}, #{typeId})")
void add(Goods good);
//添加根据商品ID查询商品的方法
@Select("select * from goods where id = #{id}")
Goods getById(int id);

//修改商品的方法
@Update("update goods set cover=#{cover}, name=#{name}, intro=#{intro}, spec=#{spec}, price=#{price}, stock=#{stock}, sales=#{sales}, content=#{content}, type_id=#{typeId} where id = #{id}")
void update(Goods good);

//删除商品
@Delete("delete from goods where id =#{id}")
void goodDelete(int id);

//    分页查询所有今日推荐商品的方法(旧)
//@Select("<script>select * from goods where id in "
//        + "<foreach item='item' index='index' collection='goodIds' open='(' separator=',' close=')'> #{item}</foreach>"
//        + " limit #{start}, #{size}</script>")
//List<Goods> getListByIds(@Param("goodIds") List<Integer> goodIds, @Param("start") int start, @Param("size") int size);
//    @Select("<script>select count(*) from goods where id in "
//            + "<foreach item='item' index='index' collection='goodIds' open='(' separator=',' close=')'> #{item}</foreach></script>")
//    int getCountByIds(@Param("goodIds") List<Integer> goodIds);
//    //查询今日推荐前六个商品
//    @Select("select * from goods g join tops t on g.id=t.good_id where t.type=#{type} order by t.id desc limit #{start}, #{size}")
//    List<Goods> selectListByTopType(@Param("type") int type, @Param("start") int start, @Param("size") int size);
//    //查询销量前前八个商品
//    @Select("select * from goods order by sales desc limit #{start}, #{size}")
//    public List<Goods> selectListOrderSales(@Param("start")int start, @Param("size")int size);
//    //查询每一种商品类型的前15个商品
//    @Select("select * from goods where type_id=#{typeId} order by id desc limit #{start}, #{size}")
//    List<Goods> selectListByTypeId(@Param("typeId")int typeId, @Param("start")int start, @Param("size")int size);


    //查推荐商品
    @Select("SELECT * FROM goods WHERE id IN(SELECT good_id FROM tops WHERE TYPE = 1)")
    List<Goods> getGoodIdsByType();


    //查询今日推荐前六个商品
    @Select("select * from goods g join tops t on g.id=t.good_id where t.type=1 order by t.id desc limit #{start}, #{size}")
    List<Goods> Sixfirst(@Param("start") int start, @Param("size") int size);

    //查询销量前前八个商品
    @Select("select * from goods order by sales desc limit #{start}, #{size}")
    List<Goods> XiaoEight(@Param("start")int start, @Param("size")int size);
    //查询热销排行
    @Select("SELECT * FROM goods ORDER BY sales DESC")
    List<Goods> XiaoPai();

    //查询每一种商品类型的前15个商品
    @Select("select * from goods where type_id=#{typeId}")
    List<Goods> Swu(@Param("typeId")int typeId);

    //查询今日推荐商品的数量
    @Select("select count(*) from goods g join tops t on g.id=t.good_id where t.type=#{type} order by t.id desc")
    long getCountByTopType(int typeId);


    //查询某一种类型商品的数量
    @Select("select count(*) from goods where type_id = #{typeId}")
    long getCountByTypeId(@Param("typeId") int typeId);

    //新品上市查询
    @Select("select * from goods order by id desc limit #{start}, #{size}")
    List<Goods> newGoods(@Param("start") int start, @Param("size") int size);

//    查询俩个今日推荐商品在商品详情页显示
    @Select("select * from goods g join tops t on g.id=t.good_id where t.type=1 order by t.id desc LIMIT 0,2")
    List<Goods> getListByTopType();
}
